import {
  ADD_STREAM_SRCS,
  SET_STREAM_SRC_CHECKED,
  SET_STREAM_SRC_ALL_UNCHECKED
} from '../mutation-types'

import _ from 'lodash'

// initial state
const state = {
  list: []
}

// mutations
const mutations = {
  [ADD_STREAM_SRCS] (state, srcType, val) {
    var streams = _.filter(state.list, (item) => {
      return item.srcType != srcType
    })
    state.list = _.concat(streams, val)
  },
  [SET_STREAM_SRC_CHECKED] (state, id, val) {
    var item = _.find(state.list, {_id: id})
    if (item) {
      item._checked = val
    }
  },
  [SET_STREAM_SRC_ALL_UNCHECKED] (state) {
    _.forEach(state.list, (item) => {
      item._checked = false
    })
  },
}

export default {
  state,
  mutations
}